menuList[1].onclick();

// 获取当月销售数据
function getMouthSalesFun(){
    axios({
        url: '/admin/trade/findChart',
        method: 'GET',
        })
        .then(data => {
            console.log(data.data);
            
          
            chartFun(data.data.data)
        })
        .catch(err => {
            console.log(err);
        })
}
// getMouthSalesFun()
//图表管理

function ceilNumber(number){
    let bite = 0;
    if(number < 10){
      return 10;
    }
    while( number >= 10 ){
      number /= 10;
      bite += 1;
    }
    return Math.ceil(number) * Math.pow(10,bite);
}
function chartFun(datas){
    var date = new Date();
    var month = date.getMonth();
    let year = date.getFullYear();
    let days;
    let maxMoney =Math.max.apply(null,datas[0])
    maxMoney = Math.ceil(maxMoney+maxMoney/3)
    let maxorders =Math.max.apply(null,datas[1])
    maxorders = Math.ceil(maxorders+maxorders/3)
    let maxorder =Math.max.apply(null,datas[2])
    maxorder = Math.ceil(maxorder+maxorder/3)
    console.log(maxMoney);
    console.log(maxorders);
    console.log(maxorder);
    if(month==1||3||5||7||8||10||12){
        days=['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12','13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24','25', '26', '27', '28', '29', '30','31']

    }else if(month==2){
        if(year%4==0&&year%100!=0){
            days=['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12','13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24','25', '26', '27', '28', '29']

        }else{
            days=['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12','13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24','25', '26', '27', '28']

        }
    }else{
        days=['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12','13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24','25', '26', '27', '28', '29', '30']
    }
    let daysArr=[];
    for(let i=1;i<=days;i++){
        daysArr[i]=toString(i);
    }
    
    var myChart = echarts.init(document.getElementById('chartWrap'));
     
    let maxOrder = Math.max.apply(null,datas[1])
    console.log(maxOrder);
    const colors = ['#5470C6', '#91CC75', '#EE6666'];
    option = {
        color: colors,
        tooltip: {
            trigger: 'axis',
            axisPointer: {
            type: 'cross'
            }
        },
        grid: {
            right: '20%'
        },
        toolbox: {
            feature: {
            dataView: { show: true, readOnly: false },
            restore: { show: true },
            saveAsImage: { show: true }
            }
        },
        legend: {
            data: ['总订单', '交易成功', '总金额']
        },
        xAxis: [
            {
            type: 'category',
            axisTick: {
                alignWithLabel: true
            },
            // prettier-ignore
            // data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12','13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24','25', '26', '27', '28', '29', '30']
            data:days
            }
        ],
        yAxis: [
            {
            type: 'value',
            name: '总订单',
            min: 0,
            max: maxorders,
            position: 'right',
            axisLine: {
                show: true,
                lineStyle: {
                color: colors[0]
                }
            },
            axisLabel: {
                formatter: '{value}单'
            }
            },
            {
            type: 'value',
            name: '交易成功',
            min: 0,
            max: maxorder,
            position: 'right',
            offset: 80,
            axisLine: {
                show: true,
                lineStyle: {
                color: colors[1]
                }
            },
            axisLabel: {
                formatter: '{value}单'
            }
            },
            {
            type: 'value',
            name: '总金额',
            min: 0,
            max: maxMoney,
            position: 'left',
            axisLine: {
                show: true,
                lineStyle: {
                color: colors[2]
                }
            },
            axisLabel: {
                formatter: '{value}元 '
            }
            }
        ],
        series: [
            {
            name: '总订单',
            type: 'bar',
            // data: [
            //     2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3
            // ]
            data:datas[1]
            },
            {
            name: '交易成功',
            type: 'bar',
            yAxisIndex: 1,
            // data: [
            //     2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3
            // ]
            data:datas[2]
            },
            {
            name: '总金额',
            type: 'line',
            yAxisIndex: 2,
            // data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
            data:datas[0]
            }
        ]
    };
    myChart.setOption(option);
}

// 关闭的函数
function closeOrderAmount(){
    let covers = document.getElementsByClassName('covers')[0]
    let chartWin = document.getElementsByClassName('chartWin')[0]
    covers.style.display = 'none';
    chartWin.style.display = 'none';
    
}
// 显示当月销售图表
function openChartFun(){
    let covers = document.getElementsByClassName('covers')[0]
    let chartWin = document.getElementsByClassName('chartWin')[0]
    covers.style.display = 'block';
    chartWin.style.display = 'block';
    getMouthSalesFun();
}